package com.kgc.scd.controller;


import com.kgc.scd.bean.UserVO;
import com.kgc.scd.service.WebWechatPayService;
import com.kgc.scd.util.RequestResult;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created On : 2022/11/4.
 * <p>
 * Author : #jiangguoqiang
 * <p>
 * Description: 微信支付接口的操作入口
 */
@Slf4j
@RestController
@Api(tags = "17、购买会员(jgq)",value = "通过微信扫描二维码支付，购买会员")

public class WebWechatPayController {

    @Autowired
    private WebWechatPayService webWechatPayService;
    /**
     * @author : Administrator
     * @date   : 2022/11/4
     * @param  : []
     * @return : com.kgc.sct.util.RequestResult<java.util.Map<java.lang.String,java.lang.Object>>
     * @description : 请求微信统一下单接口，下预支付订单，返回支付连接
     */
    @ApiOperation(value = "购买会员", notes = "根据传入的用户id和购买周数，通过微信支付购买会员")
    @ApiImplicitParam(name = "num", required = false, value = "1周1分钱，购买会员的周数 ")
    @PostMapping("/unifyOrder")
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功"),
            @ApiResponse(code = 999,message = "失败")
    })
    public RequestResult<Map<String,String>> wechatPayUnifyOrder(@RequestHeader String tokrn,@RequestParam(value = "num", required = false) Integer num) {
        return webWechatPayService.wechatPayUnifiedOrder(tokrn,num);

    }

    /**
     * @author : Administrator
     * @date   : 2022/11/17
     * @param  : [userVo]
     * @return : RequestReturn<String>
     * @description : 查询当前用户的会员到期时间
     */
    @PostMapping("/queryUserMemberDate")
    @ApiOperation(value = "查询会员时间",notes = "根据用户id来查询会员到期时间")
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功"),
            @ApiResponse(code = 999,message = "失败")
    })
    public RequestResult<String> queryUserMemberDate(@RequestBody UserVO userVo){
        return webWechatPayService.queryUserMemberDate(userVo);
    }

}
